package deep.projects.newsapp.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wuxinwudai.android.widget.ExRecyclerViewAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import deep.projects.newsapp.R;
import deep.projects.newsapp.beans.News;

/**
 * NewsAdapter 类为新闻适配器类
 * @author 吾心无待 于2016年03月05日
 */
public class NewsAdapter extends ExRecyclerViewAdapter<News,NewsAdapter.ViewHolder> {

    public NewsAdapter(Context context) {
        super(context);
    }

    @Override
    public void initViewHolder(ViewHolder viewHolder, News news) {
        Glide.with(mContext).load(news.getImageUri()).into(viewHolder.ivPic);
        viewHolder.tvTitle.setText(news.getTitle());
        viewHolder.tvTime.setText(news.getCreateTime());
        viewHolder.tvNewsCommentNumber.setText(String.valueOf(news.getCommentNo()));
    }

    @Override
    public int getRecyclerViewItemLayoutResID() {
        return R.layout.lv_item_news;
    }

    @Override
    public ViewHolder getViewHolder(View convertView) {
        return new ViewHolder(convertView);
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.iv_news_pic) ImageView ivPic;
        @BindView(R.id.tv_news_title) TextView tvTitle;
        @BindView(R.id.tv_news_time) TextView tvTime;
        @BindView(R.id.tv_news_comment_number) TextView tvNewsCommentNumber;//新闻评论数量
        public ViewHolder(View view){
            super(view);
            ButterKnife.bind(this,view);
        }
    }
}
